package com.class05.share;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @ClassDescription:
 * 演示共享域对象获取
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/6 17:02
 */
@Controller
@RequestMapping("share")
@ResponseBody
public class ShareController {
    //springmvc提供的方法：request提供了几种共享域对象(了解)
    //model modelMap Map  modelAndView
    public void data1(Model model){
//        request
       model.addAttribute("key","value");
    }

    public void data2(ModelMap model){
//        request
        model.addAttribute("key","value");
    }

    public void data3(Map model){
//        request
        model.put("key","value");
    }
    public ModelAndView data4(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("key","value");
        modelAndView.setViewName("视图名 页面名称");
//        request
        return modelAndView;

    }
}
